//
//  LDYHomeCell.swift
//  李东阳微博
//
//  Created by 李东阳 on 16/4/20.
//  Copyright © 2016年 李东阳. All rights reserved.
//

import UIKit
import SnapKit
class LDYHomeCell: UITableViewCell {

    
        //MARK: -  记录底部toolBar 的约束
    var toolBarTopConstraint:Constraint?
    
    var status:LDYStatus?{
        
        didSet{
          originaView.status = status
          retweetView.status = status
          toolBarView.status = status
            
            self.toolBarTopConstraint?.uninstall()
            
             "TODO:|FIXME: 判断是否有转发微博的逻辑    cell的复用问题 卸载约束"
            
            if status?.retweeted_status == nil{
            
                //隐藏转发微博
                retweetView.hidden = true
            toolBarView.snp_makeConstraints(closure: { (make) -> Void in
                
                 self.toolBarTopConstraint  = make.top.equalTo(originaView.snp_bottom).constraint
                
            })
                
            }else{
                
                  retweetView.hidden = false
                toolBarView.snp_makeConstraints(closure: { (make) -> Void in
                    
                     self.toolBarTopConstraint  = make.top.equalTo(retweetView.snp_bottom).constraint
                    
                })
                
            
            }
            
            
        }
        
    }
    
    
  override  init(style: UITableViewCellStyle, reuseIdentifier: String?) {
    //Mark --
   super.init(style: style, reuseIdentifier: reuseIdentifier)
    
    
     setupUI()
    }

  required init?(coder aDecoder: NSCoder) {
      fatalError("init(coder:) has not been implemented")
  }
    
    
    private func setupUI(){
    
    
   self.backgroundColor = RGB(red: 237, green: 237, blue: 237)
        
            //MARK: -  添加控件
    contentView.addSubview(originaView)
    contentView.addSubview(toolBarView)
     contentView.addSubview(retweetView)
     originaView.snp_makeConstraints { (make) -> Void in
        
            //MARK: -  设置frame
        make.top.equalTo(contentView).offset(8)
        make.left.equalTo(contentView)
        make.right.equalTo(contentView)
      "TODO:|FIXME: 已经通过文字底部判断我们原创微博的底部了"
        

//        make.height.equalTo(50)
        
        }
        
        
        retweetView.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(originaView.snp_bottom)
            make.leading.trailing.equalTo(contentView)
            
           "TODO:|FIXME: 已经在转发微博中设置高度"
//            make.height.equalTo(150)
        }
        
        
        toolBarView.snp_makeConstraints { (make) -> Void in
            make.leading.trailing.equalTo(contentView)
            make.height.equalTo(37)
           self.toolBarTopConstraint  =   make.top.equalTo(retweetView.snp_bottom).constraint
            
        }
        
     
        
        
            //MARK: -  contentView 设置frame
        contentView.snp_makeConstraints { (make) -> Void in
            make.leading.trailing.top.equalTo(self)
            make.bottom.equalTo(toolBarView.snp_bottom)
        }
        
        
    }
    

        //MARK: -   懒加载控件    01 原创微博 originaView
    private lazy var originaView:LDYStatusOriginaView = LDYStatusOriginaView()
    
          //MARK: -   懒加载控件    02 转发 评论 赞 toolBarView
   private lazy var toolBarView:LDYToolBarView = LDYToolBarView()
    
        //MARK: -  懒加载控件 03 转发微博
    private lazy var  retweetView:LDYStatusRetweetView = LDYStatusRetweetView()
    
    
    
    

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
